/* 创建整个应用的路由器 */
// 1：引入createRouter
import {createRouter, createWebHashHistory} from 'vue-router';

// 2：引入可能要呈现的组件
import HomeView from '@admin/views/HomeView.vue';
import WelcomeView from '@admin/views/WelcomeView.vue';
import LoginView from '@admin/views/LoginView.vue';
import UserView from '@admin/views/user/UserView.vue';
import MyFileView from '@admin/views/file/MyFileView.vue';
import ShareView from '@admin/views/file/ShareView.vue'
import BinView from '@admin/views/file/BinView.vue';

// 3：定义路由规则
const routes = [
    {path: '/', redirect: '/login'},
    {path: '/login', name: 'Login', component: LoginView},
    {
        path: '/home',
        component: HomeView,
        redirect: '/welcome',
        children: [
            {path: '/welcome', component: WelcomeView},
            {path: 'user', component: UserView},
            {path: 'file', component: MyFileView},
            {path: 'share', component: ShareView},
            {path: 'bin', component: BinView},
        ],
    },
];

// 4：创建路由器
const router = createRouter({
    history: createWebHashHistory(), //路由器的工作模式
    routes: routes,
});

// // 5：全局前置守卫，权限拦截
// router.beforeEach(async (to, from) => {
//     let token = localStorage.getItem('access-token')
//     if (to.path == '/login') {
//         return true
//     } else {
//         if (token) {
//             return true
//         } else {
//             return '/login'
//         }
//     }
// })

// 6：暴露出去router
export default router;
